/**
 * 
 */
$(function() {
    		
	var begindate = new Date();
	
	$("#begintime").val(begindate.getFullYear()+"-"+(begindate.getMonth()+1)+"-"+"01");
	$("#begintime").datetimepicker({
		language: "zh-CN",		
		format: "yyyy-mm-dd",	//日期格式
     	todayBtn:  "linked",	//初始固定当天日期
		todayHighlight: "true",		//当天日期高亮
		autoclose: "false",   //选中即关闭
		minView: "month",	//最小显示到“月”
    });
	
	var enddate = new Date(begindate.getTime() + 1*24*60*60*1000);
	$("#endtime").val(enddate.getFullYear()+"-"+(enddate.getMonth()+1)+"-"+enddate.getDate());
	$("#endtime").datetimepicker({
		language: "zh-CN",		
		format: "yyyy-mm-dd",	//日期格式
     	todayBtn:  "linked",	//初始固定当天日期
		todayHighlight: "true",		//当天日期高亮
		autoclose: "false",   //选中即关闭
		minView: "month",	//最小显示到“月”
    });
	
	findDeviceError();
	
	device_log(1);
	device_effect(1);
});

function findDeviceError() {
	var begintime = $("#begintime").val();
	var endtime = $("#endtime").val();
	
	$.ajax({
		type: 'post',
		url: '${pageContext.request.contextPath }/log/getDeviceError.action',
		data: {
			begintime: begintime,
			endtime: endtime
		},
		success: function(data) {
			
			deviceNum = data.deviceNum;
			loseHour = data.loseHour;
			showHighcharts(deviceNum, loseHour);
		}
	});
}
function showHighcharts(deviceNum, loseHour) {
	
	var chart = new Highcharts.Chart({
		chart: {
			type: 'column',
			renderTo: 'charts',
		},
		title: {
			text: '设备效率损失时间'
		},
		credits: {		//版权信息
			enabled: false
		},
		xAxis: {
			categories: deviceNum,
			crosshairs: true
		},
		yAxis: {
			min: 0,
			title: {
				text: '小时(h)',
			}
		},
		series: [{		//数据列
			name: '设备编号',
			data: loseHour
		}],
		toolkip: {		//数据提示框
			headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
		    pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
		         '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
		    footerFormat: '</table>',
		    shared: true,
		    useHTML: true
		}	
	
	}); 
}

function device_log(currPage) {
	
	$.ajax({
		type: 'post',
		url: '${pageContext.request.contextPath }/log/getDeviceLogError.action',
		data: {
			currPage: currPage
		},
		dataType: 'html',
		success: function(data) {
			$("#devicelog").html(data);
		}
	});
}

function device_effect(currPage){
	
	$.ajax({
		type: 'post',
		url: '${pageContext.request.contextPath }/log/getDeviceEffect.action',
		data: {
			currPage: currPage
		},
		dataType: 'html',
		success: function(data) {
			$("#device_effect").html(data);
		}
	});
}
